﻿namespace SmartConference.ErrorCode
{
    /// <summary>
    /// 封装返回结果
    /// </summary>
    [Serializable]
    public class ApiResult
    {
        public bool IsSuc { get; private set; }
        public string Message { get; private set; }
        public ApiResultCode Code { get; private set; }
        protected internal ApiResult(bool issuc, string message, ApiResultCode code)
        {
            IsSuc = issuc;
            Message = message;
            Code = code;
        }

        public static ApiResult Success(ApiResultCode code)
        {
            return new ApiResult(true, "成功！", code);
        }

        public static ApiResult Error(ApiResultCode code, string reason)
        {
            return new ApiResult(false, reason, code);
        }
    }

    public class ApiResult<T> : ApiResult
    {
        public T? Data { get; private set; }
        private ApiResult(bool issuc, string message, ApiResultCode code, T? data) : base(issuc, message, code)
        {
            Data = data;
        }

        public static ApiResult<T> Success(ApiResultCode code, T? data)
        {
            return new ApiResult<T>(true, "成功！", code, data);
        }

        public static ApiResult<T> Error(ApiResultCode code, string reason)
        {
            return new ApiResult<T>(false, reason, code, default);
        }
    }
}
